package com.tybbank.Activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.flyco.tablayout.SlidingTabLayout;
import com.tybbank.Base.BaseActivity;
import com.tybbank.Fragment.fragmentui.FHListFragment;
import com.tybbank.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/11/21 0021.
 */

public class FHListActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.SmartTabLayout)
    SlidingTabLayout SmartTabLayout;
    @BindView(R.id.vp)
    ViewPager vp;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private List<String> mTitles;
    private MyPagerAdapter mAdapter;
    private String[] strings;
    private List<String> mid;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fwbuylist);
        ButterKnife.bind(this);
        toolbar(toolbar, getString(R.string.fenhongmingxi), R.mipmap.left);
        mTitles = new ArrayList<>();
        mTitles.add(getString(R.string.tisufenhong));
        mTitles.add(getString(R.string.tuijianfenhong));
        mTitles.add(getString(R.string.tuanduifenhong));
        strings = new String[mTitles.size()];
        mid = new ArrayList<>();
        mid.add("7");
        mid.add("6");
        mid.add("8");
        mFragments.clear();
        for (int i = 0; i < mTitles.size(); i++) {
            strings[i] = mTitles.get(i);
            mFragments.add(FHListFragment.getInstance(mid.get(i)));
        }
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        SmartTabLayout.setViewPager(vp);

    }

    @Override
    public void LeftClose() {
        super.LeftClose();
        FHListActivity.this.finish();
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

    }
}
